package com.gwd.task.repository;

import com.gwd.task.entity.GroupEntity;
import com.gwd.task.model.transfer.GroupInterface;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/11/9 9:52
 */
@Repository
public interface GroupRepository extends JpaRepository<GroupEntity, Long>, JpaSpecificationExecutor<GroupEntity> {

    @Query(value = "SELECT GROUP_CONCAT(user_name) as members,user_group_group_id as groupId FROM user_group, user_info " +
            "WHERE user_group_user_id=user_id GROUP BY user_group_group_id", nativeQuery = true)
    List<GroupInterface> findByGroupList();

    @Query(value = "SELECT u FROM GroupEntity u WHERE u.remove=0")
    List<GroupEntity> findByActive();
}
